package logic

import (
	"context"
	"fmt"

	"monitor/api/internal/svc"
	"monitor/api/internal/types"

	"github.com/tal-tech/go-zero/core/logx"
	pb "monitor/rpc/status/status"
)

type StatusUploadLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewStatusUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) StatusUploadLogic {
	return StatusUploadLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *StatusUploadLogic) StatusUpload(req types.StatusUploadReq) (*types.StatusUploadResp, error) {
	// todo: add your logic here and delete this line
	// 调用 status rpc 的 StatusUpload 方法
	fmt.Printf("StatusUpload ENTER:%v\n", req)
	resp, err := l.svcCtx.Status.StatusUpload(l.ctx, &pb.StatusUploadReq{
		Sn: req.Sn, Posno: req.Posno, Ndate: req.Ndate, Ntime: req.Ntime, Tyid: req.TyId, City: req.City,
		Sver: req.Sver, Unum1: uint32(req.Unum1), Unum2: uint32(req.Unum2), Amount: uint32(req.Amount), Count: uint32(req.Count), Line: uint32(req.Line), Carno: req.Carno,
		Jd: req.Jd, Wd: req.Wd, Empid: req.Empid, Rvs1: req.Rvs1, Rvs2: req.Rvs2, Pver: uint32(req.Pver), Bver: uint32(req.Bver), Alarm: uint32(req.Alarm), Stime: req.Stime, Ctime: req.Ctime, Tenant: uint32(req.Tenant)})
	if err != nil {
		return nil, err
	}
	return &types.StatusUploadResp{Code: int(resp.Code), Msg: resp.Msg, Cmd: int(resp.Cmd)}, nil
}
